package com.ezgo.erc.service;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ezgo.erc.dao.ISysdictDao;
import com.ezgo.erc.entity.Sysdict;
import com.ezgo.erc.master.exception.DaoException;
import com.ezgo.erc.master.exception.ServiceException;
import com.ezgo.erc.master.utils.Page;

@Service
public class SysdictServiceImpl implements SysdictService {

	@Autowired
	private ISysdictDao dictDao;

	@Override
	public boolean saveDict(Sysdict sysdict) throws ServiceException {
		int effectResult = 0;
		try {
			effectResult = dictDao.insert(sysdict);
		} catch (DaoException e) {
			e.printStackTrace();
		}
		return effectResult > 0 ? true : false;
	}

	@Override
	public boolean updateDict(Sysdict sysdict) throws ServiceException {
		int effectResult = 0;
		try {
			effectResult = dictDao.update(sysdict);
		} catch (DaoException e) {
			e.printStackTrace();
		}
		return effectResult > 0 ? true : false;
	}

	@Override
	public boolean deleteDict(Long id) throws ServiceException {
		int effectResult = 0;
		try {
			effectResult = dictDao.delete(id);
		} catch (DaoException e) {
			e.printStackTrace();
		}
		return effectResult > 0 ? true : false;
	}

	@Override
	public Page<Sysdict> getDictPage(Page<Sysdict> page, Map<String, Object> map) throws ServiceException {
		RowBounds pageBounds = new RowBounds((page.getPageNo() - 1) * page.getPageSize(), page.getPageSize());
		page.setList(dictDao.getData(pageBounds, map));
		page.setCount(dictDao.getTotalCount(map));
		return page;
	}

	@Override
	public Sysdict getDict(Long id) {
		return dictDao.queryOne(id);
	}

	@Override
	public List<Sysdict> getDictList(Map<String, Object> map) {
		return dictDao.query(map);
	}

}
